{% load i18n %}
<div class="pagination">
    <span class="step-links">
    {% if page.has_previous %}
    <a href="?{% if q %}q={{ q }}&{% endif %}page={{ page.previous_page_number }}" class="previous th2">&laquo;</a>
    {% endif %}

        {% for pnum in begin %}
            {% ifequal page.number pnum %}
                <span class="current">{{ pnum }}</span>
            {% else %}
            <a href="?{% if q %}q={{ q }}&{% endif %}page={{ pnum }}" class="th2">{{ pnum }}</a>
            {% endifequal %}
        {% endfor %}

        {% if middle %}
            <span class="continue">...</span>
            {% for pnum in middle %}
                {% ifequal page.number pnum %}
                    <span class="current">{{ pnum }}</span>
                {% else %}
                <a href="?{% if q %}q={{ q }}&{% endif %}page={{ pnum }}" class="th2">{{ pnum }}</a>
                {% endifequal %}
            {% endfor %}
        {% endif %}

        {% if end %}
            <span class="continue">...</span>
            {% for pnum in end %}
                {% ifequal page.number pnum %}
                    <span class="current">{{ pnum }}</span>
                {% else %}
                <a href="?{% if q %}q={{ q }}&{% endif %}page={{ pnum }}" class="th2">{{ pnum }}</a>
                {% endifequal %}
            {% endfor %}
        {% endif %}

    {% if page.has_next %}
    <a href="?{% if q %}q={{ q }}&{% endif %}page={{ page.next_page_number }}" class="next th2">&raquo;</a>
    {% endif %}
    </span>
</div>
